﻿using System;
using System.Collections.Generic;
using BikeSystem.Models;
using Db4objects.Db4o;
using System.IO;
namespace BikeSystem.DAL
{
    public class BillService
    {
        readonly static string YapFileName = Path.Combine(Environment.CurrentDirectory, "bikesystem.yap");
        public void InsertBill(Bill bill)
        {
            using (IObjectContainer db = Db4oEmbedded.OpenFile(YapFileName))
            {
                db.Store(bill);
                Console.WriteLine("Stored {0}", bill);
            }

        }

        public IList<Bill> GetBill()
        {
            IList<Bill> bills = new List<Bill>();
            using (IObjectContainer db = Db4oEmbedded.OpenFile(YapFileName))
            {
                IObjectSet result = db.QueryByExample(typeof(Bill));
                while (result.HasNext())
                {
                    bills.Add((Bill)result.Next());
                }

                return bills;
            };

        }

    }
}
